{extend name="layout/default" /}
{block name="title"}软件修改{/block}
{block name="content"}
<form class="layui-form" action="">
    <div class="mainBox" style="background-color: white;">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">软件名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off" placeholder="请输入软件名称" value="{$info.name | default=''}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">更新配置</label>
                    <div class="layui-input-block">
                        <blockquote class="layui-elem-quote">
                            为了避免迭代版本的稳定性，软件配置新增保存后不允许二次修改。
                        </blockquote>
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>描述</th>
                                <th>键名</th>
                                <th>类型</th>
                            </tr>
                            </thead>
                            <tbody>
                            {php}
                                $configType = [
                                    'file'      => '上传',
                                    'text'      => '文本',
                                    'textarea'  => '文本域',
                                    'radio'     => '单选'
                                ];
                            {/php}
                            {volist name="info.config" id="vo"}
                                <tr>
                                    <td>{$vo.cnname}</td>
                                    <td>{$vo.enname}</td>
                                    <td>{$configType[$vo.type]}</td>
                                </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" title="正常" {if($info.status == 0)}checked{/if}>
                        <input type="radio" name="status" value="1" title="禁用" {if($info.status == 1)}checked{/if}>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="form-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script>
    layui.use(['form','jquery', 'popup'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;
        let MODULE_PATH = "/{:request()->controller()}";

        form.on('submit(form-save)', function(data){
            let roleIds = "";
            $('input[type=checkbox]:checked').each(function() {
                roleIds += $(this).val()+",";
            });
            roleIds = roleIds.substr(0,roleIds.length-1);
            data.field.roleIds = roleIds;
            let loading = layer.load();
            $.ajax({
                url: MODULE_PATH + "/edit?id={$info.id}",
                data: data.field,
                dataType:'json',
                type:'post',
                success:function(res){
                    layer.close(loading);
                    if(Number(res.code) === 0){
                        popup.success(res.msg, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dataTable");
                        });
                    }else{
                        popup.failure(res.msg);
                    }
                },
                error: function (res) {
                    layer.close(loading);
                    popup.failure("网络错误, 请重试");
                }
            })
            return false;
        });

        let tp_debug = $("#think_page_trace_open");
        (tp_debug.length > 0) && tp_debug.remove();
    })
</script>
{/block}